package com.ruoyi.paperDetail.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.paper.domain.Paper;
import com.ruoyi.paperDetail.mapper.PaperDetailMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paperDetail.domain.PaperDetail;
import com.ruoyi.paperDetail.service.IPaperDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 论文信息内容展示Controller
 * 
 * @author moyu
 * @date 2023-03-07
 */
@Api("论文信息内容展示")
@RestController
@RequestMapping("/paperDetail/paperDetail")
public class PaperDetailController extends BaseController
{
    @Autowired
    private IPaperDetailService paperDetailService;

    /**
     * 查询论文信息内容展示列表
     */
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaperDetail paperDetail)
    {
        startPage();
        List<PaperDetail> list = paperDetailService.selectPaperDetailList(paperDetail);
        return getDataTable(list);
    }

    /**
     * 导出论文信息内容展示列表
     */
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:export')")
    @Log(title = "论文信息内容展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperDetail paperDetail)
    {
        List<PaperDetail> list = paperDetailService.selectPaperDetailList(paperDetail);
        ExcelUtil<PaperDetail> util = new ExcelUtil<PaperDetail>(PaperDetail.class);
        util.exportExcel(response, list, "论文信息内容展示数据");
    }

    /**
     * 获取论文信息内容展示详细信息
     */
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paperDetailService.selectPaperDetailById(id));
    }

    /**
     * 新增论文信息内容展示
     */
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:add')")
    @Log(title = "论文信息内容展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperDetail paperDetail)
    {
        return toAjax(paperDetailService.insertPaperDetail(paperDetail));
    }

    /**
     * 修改论文信息内容展示
     */
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:edit')")
    @Log(title = "论文信息内容展示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperDetail paperDetail)
    {
        return toAjax(paperDetailService.updatePaperDetail(paperDetail));
    }

    /**
     * 删除论文信息内容展示
     */
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:remove')")
    @Log(title = "论文信息内容展示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperDetailService.deletePaperDetailByIds(ids));
    }

    /**
     * 上传
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @Log(title = "论文基本数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('paperDetail:paperDetail:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<PaperDetail> util = new ExcelUtil<>(PaperDetail.class);
        //stuList里面有全部的数据
        List<PaperDetail> paperDetailList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = paperDetailService.importPaper(paperDetailList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
     * 下载模板
     * @param response
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<PaperDetail> util = new ExcelUtil<>(PaperDetail.class); // todo
        util.importTemplateExcel(response, "论文基本信息");
    }




}
